package com.jiakai.cashinterfacemucon.controller;


import com.jiakai.cashinterfacemucon.model.Relation;
import com.jiakai.cashinterfacemucon.service.RelationService;
import com.lishunyi.result.VO.ResultVO;
import com.lishunyi.result.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cashinterface")
public class RelationController {

    @Autowired
    private RelationService relationService;
    @RequestMapping("/relation/add")
    public ResultVO addYKRelation(String productID, String PID3rd){
        Relation relation = new Relation();
        relation.setProductID(productID);
        relation.setPID3rd(PID3rd);
        int flag = relationService.insert(relation);
        if (flag <= 0){
            return ResultUtils.error(999,"增加失败");
        }
        return ResultUtils.success();
    }

    @RequestMapping("/relation/del")
    public ResultVO delYKRelation(String productID){
        int flag = relationService.deleteByProductID(productID);
        if (flag <= 0){
            return ResultUtils.error(999,"删除失败");
        }
        return ResultUtils.success();
    }

    @RequestMapping("/relation/sel")
    public ResultVO selYKRelatioin(String productID){
        List<Relation> relations = relationService.selectByProductID(productID);
        return ResultUtils.success(relations);
    }
}
